import {
	defineStore
} from 'pinia';

const wash = defineStore({
	id: 'playlet',
	state: () => ({
		userPlayList: []
	}),
	actions: {
		getDePlay(id) {
			console.log(this.userPlayList.find(item => item.id === id).de_list)
			return this.userPlayList.find(item => item.id === id).de_list
		},
		isPlay(id) {
			return this.userPlayList.some(item => item.id === id)
		},
		setPlay(id, list) {
			this.userPlayList.push({
				id: id,
				de_list: list
			})
		},
		updatePlay(id, sort) {
			let index = this.userPlayList.findIndex(item => item.id === id)
			
			if (index !== -1) {
				this.userPlayList[index].de_list.push(sort)
			}
		}
	},
	persist: {
		enabled: true,
		strategies: [{
			key: 'playlet',
			storage: localStorage, //存储的位置，默认为sessionStorage
		}, ],
	},
});

export default wash;